Elementos de Álgebra Lineal

LES RECOMIENDO checar:

Libros/Cursos en la red:

ALGEBRA LINEAL CON JULIA Stephen Boyd & Lieven Vandenberghe
https://web.stanford.edu/~boyd/vmls/

3BLUE1BROWN EXCELENTE!
https://www.youtube.com/c/3blue1brown

GILBERT STRANG MIT
https://math.mit.edu/~gs/

Lenguajes de Programación:

Julia

https://julialang.org/

https://github.com/fonsp/Pluto.jl

Anaconda Python

[https://docs.anaconda.com/anaconda/install/(https://docs.anaconda.com/anaconda/install/)

1)Sistemas de Ecuaciones lineales

2)Formulación matricial, Espacios vectoriales,columna,renglón,bases

3)Sistemas determinados, sobre,sub

4)Cuadrados mínimos

5)Problema eigenvectores,eigenvalores

5)Descomposición de valor singular

7)matrices,rotaciones,números complejos

using Symbolics
 using LinearAlgebra,Latexify, Printf,WGLMakie#,Plots
WGLMakie.activate!()
@variables x y z

$$\begin{equation} \left[ \begin{array}{c} x \\ y \\ z \\ \end{array} \right] \end{equation}$$

round4 (generic function with 1 method)

Sistemas de ecuaciones lineales

$$\begin{equation} \left[ \begin{array}{c} x + 2 y \\ 2 x + 4 y \\ \end{array} \right] = \left[ \begin{array}{c} 0 \\ 0 \\ \end{array} \right] \end{equation}$$

latexify(A*[x;y;z] ~ [2;0;0])

$$\begin{equation} \left[ \begin{array}{c} x + 3 y + 5 z \\ 4 x + 5 y + 6 z \\ 7 x + 8 y + 11 z \\ \end{array} \right] = \left[ \begin{array}{c} 2 \\ 0 \\ 0 \\ \end{array} \right] \end{equation}$$

(f ~ [3;0;0])

$$\begin{equation} \left[ \begin{array}{c} x + 3 y + 5 z \\ 4 x + 5 y + 6 z \\ 7 x + 8 y + 11 z \\ \end{array} \right] = \left[ \begin{array}{c} 3 \\ 0 \\ 0 \\ \end{array} \right] \end{equation}$$

$$\begin{equation} \left[ \begin{array}{c} x \\ y \\ z \\ \end{array} \right] = \left[ \begin{array}{c} -1 \\ 0.2857 \\ 0.4286 \\ \end{array} \right] \end{equation}$$

El sistema de ecuaciones lo podemos escribir de esta forma

$$x * \vec{col_1A} + y * \vec{col_2A}+ z * \vec{col_3A} $$

begin

#using Latexify
struct Ket{T}
    x::T
end	
@latexrecipe function f(x::Ket)
return Expr(:latexifymerge, "", x.x, "")
end
latexify(:(x*$(Ket(A[:,1])) + y*$(Ket(A[:,2]))+z*$(Ket(A[:,3]))))
end

$$x \cdot \left[ \begin{array}{c} 1 \\ 4 \\ 7 \\ \end{array} \right] + y \cdot \left[ \begin{array}{c} 3 \\ 5 \\ 8 \\ \end{array} \right] + z \cdot \left[ \begin{array}{c} 5 \\ 6 \\ 11 \\ \end{array} \right]$$

El sistema de ecuaciones de 2x2

begin
#Symbolics.solve_for([f1[1] ~ 1.0,f1[2] ~ 0.0],[x y])
Bb=copy(B)
Bb=Bb+([0.5 0;0 0])
#f3=B*[x;y];
f3=Bb*[x;y]
#f3=(B+ones(2,2))*[x;y];
(f3~[2; 2])
end

$$\begin{equation} \left[ \begin{array}{c} 1.5 x + 2 y \\ 2 x + 4 y \\ \end{array} \right] = \left[ \begin{array}{c} 2 \\ 2 \\ \end{array} \right] \end{equation}$$

La solución del sistem es:

begin
fsol3=Symbolics.solve_for([f3[1] ~ 2.0,f3[2] ~ 2.0],[x y])
latexify(("[x,y]" ~ [round4(fsol3[1]);round4(fsol3[2])]))

#t1*string(fsol3)"
#println("The solution is [x,y,z]= " * string(fsol3))
end

$$\begin{equation} \left[ \begin{array}{c} x \\ y \\ \end{array} \right] = \left[ \begin{array}{c} 2 \\ -0.5 \\ \end{array} \right] \end{equation}$$

$$\begin{equation} \mathrm{ones}\left( 3, 3 \right) = \left[ \begin{array}{ccc} 1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \\ \end{array} \right] \end{equation}$$

Otros sistemas y su soluciones

@bind mfac1 Slider(-10.0:10.0,show_value=true,default=1)
1.0

$$\begin{equation} M1 = \left[ \begin{array}{ccc} 1 & 3 & 5 \\ 3 & 6 & 10 \\ 1 & 0 & 4.5 \\ \end{array} \right] \end{equation}$$

$$\begin{equation} rango = 3 \end{equation}$$

$$\begin{equation} \left[ \begin{array}{c} x + 3 y + 5 z \\ 2 \left( x + 3 y + 5 z \right) + x \\ x + 4.5 z \\ \end{array} \right] = \left[ \begin{array}{c} 1 \\ 2 \\ 1 \\ \end{array} \right] \end{equation}$$

$$\begin{equation} \left[ \begin{array}{c} x \\ y \\ z \\ \end{array} \right] = \left[ \begin{array}{c} -0 \\ -0.037 \\ 0.2222 \\ \end{array} \right] \end{equation}$$

Operaciones elementales, pivotes, descomposición LU

$$\begin{equation} A = \left[ \begin{array}{ccc} 1 & 3 & 5 \\ 4 & 5 & 6 \\ 7 & 8 & 11 \\ \end{array} \right] \end{equation}$$

begin
#A+[0 0 0;2 -1 0;1 0 -1]*A
#A+[0 0 0;0 0 0;1 0 -1]*A
P1=[1 0 0;4 -1 0;0 0 1]
P2=[1 0 0; 0 1 0;7 0 -1]
P3=[1 0 0; 0 1 0;0 13//7 -1]
PA=P1*A
PPA=P2*PA
PPPA=P3*PPA
latexify("P1" ~ [1 0 0;4 -1 0;0 0 1]),
latexify("P1A" ~ PA),
latexify("P2" ~ [1 0 0; 0 1 0;7 0 -1]),
latexify("P2P1A" ~ PPA),
latexify("P3" ~ [1 0 0; 0 1 0;0 13//7 -1]),
latexify("P1P2P3A" ~ PPPA)
end
#latexify(rank([1 3 5;2 6 10;1 2 0]))
(L"\begin{equation}
P1 = \left[
\begin{array}{ccc}
1 & 0 & 0 \\
4 & -1 & 0 \\
0 & 0 & 1 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
P1A = \left[
\begin{array}{ccc}
1 & 3 & 5 \\
0 & 7 & 14 \\
7 & 8 & 11 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
P2 = \left[
\begin{array}{ccc}
1 & 0 & 0 \\
0 & 1 & 0 \\
7 & 0 & -1 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
P2P1A = \left[
\begin{array}{ccc}
1 & 3 & 5 \\
0 & 7 & 14 \\
0 & 13 & 24 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
P3 = \left[
\begin{array}{ccc}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & \frac{13}{7} & -1 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
P1P2P3A = \left[
\begin{array}{ccc}
1 & 3 & 5 \\
0 & 7 & 14 \\
0 & 0 & 2 \\
\end{array}
\right]
\end{equation}
")
@bind indp Slider(1:3,show_value=true,default=1)
1
begin
PS=("P"*string(indp));
PSE=eval(Meta.parse(PS))
PSEI=inv(PSE)
latexify(PS ~ PSE),
if indp < 3
latexify(PS*"^-1" ~ Int.(PSEI))
else
latexify(PS*"^-1" ~ PSEI)
end
#latexify(PS),
#latexify(inv(PS))
end
(L"\begin{equation}
P1 = \left[
\begin{array}{ccc}
1 & 0 & 0 \\
4 & -1 & 0 \\
0 & 0 & 1 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
P1^{-1} = \left[
\begin{array}{ccc}
1 & 0 & 0 \\
4 & -1 & 0 \\
0 & 0 & 1 \\
\end{array}
\right]
\end{equation}
")
latexify("A" ~ A),
latexify("SP" ~ [1 0 0;4 -1 -1;0 0 1]),
latexify("SPA" ~ [1 0 0;4 -1 -1;0 0 1]*A),
latexify("4row1A-row2A-row3A" ~ [4*A[1,:]-A[:2,:]-A[3,:]]')

(L"\begin{equation}
A = \left[
\begin{array}{ccc}
1 & 3 & 5 \\
4 & 5 & 6 \\
7 & 8 & 11 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
SP = \left[
\begin{array}{ccc}
1 & 0 & 0 \\
4 & -1 & -1 \\
0 & 0 & 1 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
SPA = \left[
\begin{array}{ccc}
1 & 3 & 5 \\
-7 & -1 & 3 \\
7 & 8 & 11 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
4 row1A - row2A - row3A = \left[
\begin{array}{c}
\left[
\begin{array}{ccc}
-7 & -1 & 3 \\
\end{array}
\right] \\
\end{array}
\right]
\end{equation}
")
inv([1 0 0;4 -1 -1;0 0 1])
3×3 Matrix{Float64}:
 1.0   0.0  -0.0
 4.0  -1.0  -1.0
 0.0   0.0   1.0

Descompoisición LU, A LU?

(L"\begin{equation}
L = \left[
\begin{array}{ccc}
1 & 0 & 0 \\
0.1429 & 1 & 0 \\
0.5714 & 0.2308 & 1 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
U = \left[
\begin{array}{ccc}
7 & 8 & 11 \\
0 & 1.8571 & 3.4286 \\
0 & 0 & -1.0769 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
LU = \left[
\begin{array}{ccc}
7 & 8 & 11 \\
1 & 3 & 5 \\
4 & 5 & 6 \\
\end{array}
\right]
\end{equation}
")
Hay una permutación de renglones de por medio en el proceso!

$$PA = LU$$

(L"\begin{equation}
A = \left[
\begin{array}{ccc}
1 & 3 & 5 \\
4 & 5 & 6 \\
7 & 8 & 11 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
P = \left[
\begin{array}{ccc}
0 & 0 & 1 \\
1 & 0 & 0 \\
0 & 1 & 0 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
PA = \left[
\begin{array}{ccc}
7 & 8 & 11 \\
1 & 3 & 5 \\
4 & 5 & 6 \\
\end{array}
\right]
\end{equation}
")

$$\begin{equation} P^{-1} LU = \left[ \begin{array}{ccc} 1 & 3 & 5 \\ 4 & 5 & 6 \\ 7 & 8 & 11 \\ \end{array} \right] \end{equation}$$

permuta renglones 1-> 2, 2 -> 3, 3 -> 1

$$\begin{equation} P \left[ \begin{array}{c} 0 \\ 0 \\ 1 \\ \end{array} \right] = \left[ \begin{array}{c} 1 \\ 0 \\ 0 \\ \end{array} \right] \end{equation}$$

$$\begin{equation} P \left[ \begin{array}{c} 1 \\ 0 \\ 0 \\ \end{array} \right] = \left[ \begin{array}{c} 0 \\ 1 \\ 0 \\ \end{array} \right] \end{equation}$$

latexify(("P"~ FLU.P))

$$\begin{equation} P = \left[ \begin{array}{ccc} 0 & 0 & 1 \\ 1 & 0 & 0 \\ 0 & 1 & 0 \\ \end{array} \right] \end{equation}$$

$$\begin{equation} U = L^{-1} PA = \left[ \begin{array}{ccc} 7 & 8 & 11 \\ 0 & 1.8571 & 3.4286 \\ 0 & 0 & -1.0769 \\ \end{array} \right] \end{equation}$$

$$PA = LU, PAx = Pb, LUx = Pb, Ux = c, Lc = Pb$$

Resuelve para c (sistema Lc=Pb ) y luego resuelve Ux=c para obtener x

$$\begin{equation} c = L^{-1} P \left[ \begin{array}{c} 2 \\ 0 \\ 0 \\ \end{array} \right] = \left[ \begin{array}{c} 0 \\ 2 \\ -0.4615 \\ \end{array} \right] \end{equation}$$

3-element Vector{Float64}:
  0.0
  2.0
 -0.4615384615384618
(L"$U \cdot \left[
\begin{array}{c}
x \\
y \\
z \\
\end{array}
\right] = c$", L"\begin{equation}
\left[
\begin{array}{c}
7 x + 8 y + 11 z \\
1.8571 y + 3.4286 z \\
 - 1.0769 z \\
\end{array}
\right] = \left[
\begin{array}{c}
0 \\
2 \\
-0.462 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
\left[
\begin{array}{c}
x \\
y \\
z \\
\end{array}
\right] = \left[
\begin{array}{c}
-1 \\
0.2857 \\
0.4286 \\
\end{array}
\right]
\end{equation}
")

La solución 'back slash' [x;y;z]=A\b

begin
Definimos la función

function lf0(A,b)
return A\b
end

[x y, z]=lf0(A,[b1;b2;b3])
end
#Defined above remember!
#using Latexify
#struct Ket{T}
#    x::T
#end	
#@latexrecipe function f(x::Ket)
#return Expr(:latexifymerge, "", x.x, "")
#end

begin
lf0(A,b)=A\b
xsol0=lf0(A,[2.0;0.0;0.0])
#strAb=(A\b)
b3=[2.0;0.0;0.0]
#latexify(:(x*$(Ket(A[:,1])) + y*$(Ket(A[:,2]))+z*$(Ket(A[:,3])))),
latexify(:($(Ket(A[:,:]))*[x;y;z] = [b1;b2;b3])),#*[x;y;z]), #+ y*$(Ket(A[:,2]))+z*$(Ket(A[:,3])))),
latexify("b" ~ b3),
#latexify(strAb)
latexify(("[x,y,z]" ~ round.(xsol0,digits=4)))
end
(L"$\left[
\begin{array}{ccc}
1 & 3 & 5 \\
4 & 5 & 6 \\
7 & 8 & 11 \\
\end{array}
\right] \cdot \left[
\begin{array}{c}
x \\
y \\
z \\
\end{array}
\right] = \left[
\begin{array}{c}
b1 \\
b2 \\
b3 \\
\end{array}
\right]$", L"\begin{equation}
b = \left[
\begin{array}{c}
2 \\
0 \\
0 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
\left[
\begin{array}{c}
x \\
y \\
z \\
\end{array}
\right] = \left[
\begin{array}{c}
-1 \\
0.2857 \\
0.4286 \\
\end{array}
\right]
\end{equation}
")

Cambia el lado derecho de la ecuación y resuelve x=A\b

latexify("b" ~ [-2,1.0,2.0] )

$$\begin{equation} b = \left[ \begin{array}{c} -2 \\ 1 \\ 2 \\ \end{array} \right] \end{equation}$$

begin
lf(A,b)=A\b
xsol1=lf(A,[-2.0;1.0;2.0])
latexify(("[x,y,z]" ~ round.(xsol1,digits=3)))

end

$$\begin{equation} \left[ \begin{array}{c} x \\ y \\ z \\ \end{array} \right] = \left[ \begin{array}{c} 1.5 \\ -0.571 \\ -0.357 \\ \end{array} \right] \end{equation}$$

Cuadrados mínimos, caso típico de problema sobre-determinado

@bind inoise Slider(0.0:0.2:5,show_value=true,default=1)
1.0
begin
flsq = Figure(size = (500, 500))
axl=Axis(flsq[1, 1], backgroundcolor = "beige")
tt=LinRange(0,10,100);
#tt=0:.1:10.0;
noise=inoise*randn(length(tt));
Att=[tt[:] ones(length(tt),1)];
xv=[1.0,3.5];
xlsq=lf0(Att,Att*xv+noise);
yobs=Att*xv.+noise
yv=Att*xv
ylsq=Att*xlsq
pointsobs = Point2f.(tt, yobs)
pointsv=Point2f.(tt, yv)
lines!(axl,pointsv,linewidth=4.0,color=:black)
scatter!(axl,pointsobs)
lines!(axl,tt,ylsq,linewidth=4.0,color=:red)
#scatter(tt,Att*xv+noise)#plot(tt,Att*xlsq,color=:red)
#lines(tt,yv)
#xlsq=lf0(Att,Att*xv+noise);
#size(noise)
#size(Att*xv)
#limits!(axl,0.0,10.0,0.0,16.0)
flsq
end
begin
latexify("xlsq" ~ round4.(xlsq)),
latexify("xv" ~ xv)
end
(L"\begin{equation}
xlsq = \left[
\begin{array}{c}
0.9734 \\
3.4544 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
xv = \left[
\begin{array}{c}
1 \\
3.5 \\
\end{array}
\right]
\end{equation}
")

$A^t(A\vec{x} -b)= 0$

$A^tA\vec{x} = A^tb)$

$\vec{x} = (A^tA)^{-1}A^tb)$

Las diferencias (residuos) deben ser ortogonales al espacio columna de A
begin
slsq=L"$A^t(A\vec{x} -b)"
latexify(slsq ~ Att'*(Att*xlsq-yobs))
end

$$\begin{equation} $A^t(A\vec{x} -b) = \left[ \begin{array}{c} 9.5213 \cdot 10^{-13} \\ 1.6076 \cdot 10^{-13} \\ \end{array} \right] \end{equation}$$

Eigenvalores/Eigenvectores (Matrices cuadradas)

$A*\vec{v}_j=\lambda_{j} \vec{v}_{j}$

$\Lambda = \begin{bmatrix} \lambda_{1} & & \\ & \ddots & \\ & & \lambda_{n} \end{bmatrix}$

$AV = \begin{bmatrix} A\vec{v}_1 & A\vec{v}_2 & \ldots & A\vec{v}_n\end{bmatrix}= \begin{bmatrix} \lambda_{1} \vec{v}_1 & \lambda_{2} \vec{v}_2 & \ldots & \lambda_{n} \vec{v}_n\end{bmatrix}$

$A*V=V*\Lambda$

$V^{-1}*A*V=\Lambda$

$V*\Lambda*V^{-1}=A$

Descomposición en Valores Singulares (SVD)

$A^{m\times n} = U^{m \times m} S^{m \times n} V^{T{(n \times n })}$

$U^{T}*U= I^{m \times m}, V^{T}*V= I^{n \times n}$

U, V tienen columnas ortonormales

begin
@variables a[1:2,1:2]
function g(a,c)
    return a=c
end
end
g (generic function with 1 method)
latexify("aa" ~ aa)

$$\begin{equation} aa = \left[ \begin{array}{cc} 0 & 1 \\ 1 & 1 \\ \end{array} \right] \end{equation}$$

latexify(round4.(L1))

$$\begin{equation} \left[ \begin{array}{c} -0.618 \\ 1.618 \\ \end{array} \right] \end{equation}$$

begin
    aa=g(a,[0 1;1 1]);
L1,V1=eigen(aa)
    latexify(["L = (V^-1)aa(V)" ~ round.(inv(V1)*aa*(V1),digits=4)])
#	V1*diagm(L1)*inv(V1)
end
    

$$\begin{align} L = V^{-1} \mathrm{aa}\left( V \right) =& \left[ \begin{array}{cc} -0.618 & -0 \\ -0 & 1.618 \\ \end{array} \right] \end{align}$$

latexify("eigvecs" ~ round4.(V1))

$$\begin{equation} eigvecs = \left[ \begin{array}{cc} -0.8507 & 0.5257 \\ 0.5257 & 0.8507 \\ \end{array} \right] \end{equation}$$

begin
ff = Figure(size = (500, 500))
ax=Axis(ff[1, 1], backgroundcolor = "beige")
xs = LinRange(-10, 10, 21)
ys = LinRange(-10, 10, 21)
us = [1.0 for x in xs, y in ys]
vs = [0.0 for x in xs, y in ys]
strength = vec(sqrt.(us .^ 2 .+ vs .^ 2))
#arrows!(xs, ys, us, vs, arrowsize = 10, lengthscale = 1.0, arrowcolor = strength, linecolor = :yellow)
#arrows!(xs, ys, vs, us, arrowsize = 10, lengthscale = 1.0, arrowcolor = strength, linecolor = :yellow)
strength2 = vec(sqrt.(V1[:,1] .^ 2 .+ V1[:,2].^ 2))
arrows!(ax,[0;0], [0;0], V1[1,:], V1[2,:],arrowsize =15.0 , lengthscale =1.,arrowcolor = strength2, linecolor =:red,linewidth=2.5)
#arrows!(ax,[0;0], [0;0], [0;1], [1;0],arrowsize =15.0 , lengthscale =1.,arrowcolor =[1;1], linecolor =:black)
arrows!(ax,[0;V1[1,1]],[0;0],[V1[1,1],0],[0,V1[2,1]],arrowsize =15.0 , lengthscale =1.,arrowcolor =[1;1], linecolor =:black)
arrows!(ax,[0;V1[1,2]],[0;0],[V1[1,2],0],[0,V1[2,2]],arrowsize =15.0 , lengthscale =1.,arrowcolor =[1;1], linecolor =:black)
θ=-atan(V1[2,2]/V1[1,2]);
θ=π/3
r90=[cos(θ) -sin(θ);sin(θ) cos(θ)];
V2=r90*V1;
arrows!(ax,[0;0], [0;0], V2[1,:], V2[2,:],arrowsize =15.0 , lengthscale =1.,arrowcolor = strength2, linecolor =:green,linewidth=2.5)
#arrows!(ax,[0;V1[1,1]],[0;0],[V1[1,1],0],[0,V1[2,1]],arrowsize =15.0 , lengthscale =1.,arrowcolor =[1;1], linecolor =:black)
#arrows!(ax,[0;0], [0;0], [0;1], [1;0],arrowsize =15.0 , lengthscale =1.,arrowcolor =[1;1], linecolor =:black)
limits!(ax, -1, 1, -1, 1)
ff
end
begin
LA,VA=eigen(A);
latexify("A" ~ A),
latexify("eivalsA" ~ round4.(LA)),
latexify("eigvecsA" ~ round4.(VA))
end
(L"\begin{equation}
A = \left[
\begin{array}{ccc}
1 & 3 & 5 \\
4 & 5 & 6 \\
7 & 8 & 11 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
eivalsA = \left[
\begin{array}{c}
-1.7177 \\
0.4461 \\
18.272 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
eigvecsA = \left[
\begin{array}{ccc}
0.9064 & 0.2413 & 0.3198 \\
-0.2148 & -0.8437 & 0.4687 \\
-0.3638 & 0.4795 & 0.8235 \\
\end{array}
\right]
\end{equation}
")
cc=[2 3;4 6]
2×2 Matrix{Int64}:
 2  3
 4  6
kk=(cc+ ones(2,2))*[x y]'

$$\begin{equation} \left[ \begin{array}{c} 3 x + 4 y \\ 5 x + 7 y \\ \end{array} \right] \end{equation}$$

Symbolics.solve_for([kk[1] ~ 1,kk[2] ~ 1.5],[x y])
2-element Vector{Float64}:
  1.0000000000000009
 -0.5000000000000007
0
Uc,S,Vc=svd(cc);
#-.5*cc[:,1]
cc
2×2 Matrix{Int64}:
 2  3
 4  6
begin
function xx(yy)
return [-1.5yy,yy]
end
#xx[1.0]
end
xx (generic function with 1 method)
begin
ff1 = Figure(size = (800, 800))
ax1=Axis(ff1[1, 1], backgroundcolor = "black")
#for l=-10:10
l=LinRange(-10, 10, 21)
xn=xx.(l)
#scatter!(ax1,xn[1],xn[2])#,xn[1]*cc[:,1]+xn[2]*cc[:,2])
#end

end
21-element Vector{Vector{Float64}}:
 [15.0, -10.0]
 [13.5, -9.0]
 [12.0, -8.0]
 [10.5, -7.0]
 [9.0, -6.0]
 [7.5, -5.0]
 [6.0, -4.0]
 ⋮
 [-7.5, 5.0]
 [-9.0, 6.0]
 [-10.5, 7.0]
 [-12.0, 8.0]
 [-13.5, 9.0]
 [-15.0, 10.0]
begin
x1s=[xn[l1][1] for l1=1:length(l)];
y1s=[xn[l1][2] for l1=1:length(l)];
end
21-element Vector{Float64}:
 -10.0
  -9.0
  -8.0
  -7.0
  -6.0
  -5.0
  -4.0
   ⋮
   5.0
   6.0
   7.0
   8.0
   9.0
  10.0

Combinaciones lineales de las columnas de la matriz (lin indep) me dan cualquier vector

latexify("cc"~ cc)

$$\begin{equation} cc = \left[ \begin{array}{cc} 2 & 3 \\ 4 & 6 \\ \end{array} \right] \end{equation}$$

Vector $[50,10]$ lo puedo escribir como

latexify(10*cc[:,1]+10*cc[:,2] -100*cc[:,1] + 200/3*cc[:,2])

$$\begin{equation} \left[ \begin{array}{c} 50.0 \\ 100.0 \\ \end{array} \right] \end{equation}$$

factor=[-5:5];
begin
ff0 = Figure(size= (500, 500))
ax0=Axis(ff0[1, 1], backgroundcolor = "beige")
#scatter(xs,ys)
#scatter(2l,4l)
scatter!(vec([xs ys]),vec([-ys xs]))
limits!(-20,20,-20,20)
ff0
end

$$\begin{equation} \left[ \begin{array}{ccc} 1 & 0 & -1 \\ -1 & 1 & -1 \\ 1 & -2 & 3 \\ \end{array} \right] \end{equation}$$

descomposición QR, A=QR

Q, Orthogonal, R upper triangular

(L"\begin{equation}
R = \left[
\begin{array}{ccc}
-1.7321 & 1.7321 & -1.7321 \\
0 & -1.4142 & 2.8284 \\
0 & 0 & 0 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
Q = \left[
\begin{array}{ccc}
-0.5774 & -0.7071 & 0.4082 \\
0.5774 & 0 & 0.8165 \\
-0.5774 & 0.7071 & 0.4082 \\
\end{array}
\right]
\end{equation}
")
(L"\begin{equation}
QR = \left[
\begin{array}{ccc}
1 & -0 & -1 \\
-1 & 1 & -1 \\
1 & -2 & 3 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
BB = \left[
\begin{array}{ccc}
1 & 0 & -1 \\
-1 & 1 & -1 \\
1 & -2 & 3 \\
\end{array}
\right]
\end{equation}
")
(L"\begin{equation}
E1 = \left[
\begin{array}{ccc}
1 & 0 & 0 \\
1 & 1 & 0 \\
0 & 0 & 1 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
E2 = \left[
\begin{array}{ccc}
1 & 0 & 0 \\
0 & 1 & 0 \\
-1 & 0 & 1 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
E3 = \left[
\begin{array}{ccc}
1 & 0 & 0 \\
1 & 0 & 0 \\
0 & 2 & 1 \\
\end{array}
\right]
\end{equation}
")
(L"\begin{equation}
BB = \left[
\begin{array}{ccc}
1 & 0 & -1 \\
-1 & 1 & -1 \\
1 & -2 & 3 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
E1 BB = \left[
\begin{array}{ccc}
1 & 0 & -1 \\
0 & 1 & -2 \\
1 & -2 & 3 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
E2 E1 BB = \left[
\begin{array}{ccc}
1 & 0 & -1 \\
0 & 1 & -2 \\
0 & -2 & 4 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
E3 E2 E1 BB = \left[
\begin{array}{ccc}
1 & 0 & -1 \\
1 & 0 & -1 \\
0 & 0 & 0 \\
\end{array}
\right]
\end{equation}
")
@bind d1 PlutoUI.Slider([[i  2i -i] for i in -2:2],show_value=true,default=1)
[-2 -4 2] [-3.0 -8.0 -2.0]
@bind  d3 PlutoUI.Slider([[3k -k/5 4k] for k in -2:2],show_value=true,default=1)
[-6.0 0.4 -8.0]
begin
Md=[d1;d2;d3]
    latexify(Md)
end

$$\begin{equation} \left[ \begin{array}{ccc} -2.0 & -4.0 & 2.0 \\ -3.0 & -8.0 & -2.0 \\ -6.0 & 0.4 & -8.0 \\ \end{array} \right] \end{equation}$$

3-element Vector{Float64}:
 -0.9467
  0.1444
  0.3422

$$\begin{equation} L = \left[ \begin{array}{ccc} -10.297+0\mathit{i} & 0.0\mathit{i} & 0.0\mathit{i} \\ 0.0\mathit{i} & -3.8517-1.6267\mathit{i} & 0.0\mathit{i} \\ 0.0\mathit{i} & 0.0\mathit{i} & -3.8517+1.6267\mathit{i} \\ \end{array} \right] \end{equation}$$

$$\begin{equation} V = \left[ \begin{array}{ccc} -0.2586+0\mathit{i} & 0.5478-0.2079\mathit{i} & 0.5478+0.2079\mathit{i} \\ -0.804+0\mathit{i} & -0.0609+0.1265\mathit{i} & -0.0609-0.1265\mathit{i} \\ -0.5354+0\mathit{i} & -0.7981+0\mathit{i} & -0.7981+0\mathit{i} \\ \end{array} \right] \end{equation}$$

round4.((rand(3,1)+im*rand(3,1))*10)
3×1 Matrix{ComplexF64}:
 3.5306 + 8.741im
 5.7847 + 8.9922im
 3.3642 + 8.2315im
LinearProblem. In-place: true
b: 3×1 Matrix{Float64}:
  8.34
 14.279
 15.647
begin
t=LinRange(0.0,100,200);
At=[ones(200,1) t];
bt=rand(200,1)*10.0;
xt=inv(transpose(At)*At)*transpose(At)*bt
xt2=At\bt
xt3=pinv(At)*bt
typeof(vec(bt))
(xt4,stats) = cgls(At,vec(bt))
latexify(["xt" ~ round4.(xt), "xt2" ~ round4.(xt3),"xt3" ~ round4.(xt3), "xt4" ~ round4.(xt4)])
end

$$\begin{align} xt =& \left[ \begin{array}{c} 4.854 \\ -0.0023 \\ \end{array} \right] \\ xt2 =& \left[ \begin{array}{c} 4.854 \\ -0.0023 \\ \end{array} \right] \\ xt3 =& \left[ \begin{array}{c} 4.854 \\ -0.0023 \\ \end{array} \right] \\ xt4 =& \left[ \begin{array}{c} 4.854 \\ -0.0023 \\ \end{array} \right] \end{align}$$

latexify(round4.(EM.vectors)),
latexify(round4.(EM.vectors')),
latexify(round4.(conj.(EM.vectors)))
(L"\begin{equation}
\left[
\begin{array}{ccc}
-0.2586+0.0\mathit{i} & 0.5478-0.2079\mathit{i} & 0.5478+0.2079\mathit{i} \\
-0.804+0.0\mathit{i} & -0.0609+0.1265\mathit{i} & -0.0609-0.1265\mathit{i} \\
-0.5354+0.0\mathit{i} & -0.7981+0.0\mathit{i} & -0.7981+0.0\mathit{i} \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
\left[
\begin{array}{ccc}
-0.2586+0.0\mathit{i} & -0.804+0.0\mathit{i} & -0.5354+0.0\mathit{i} \\
0.5478+0.2079\mathit{i} & -0.0609-0.1265\mathit{i} & -0.7981+0.0\mathit{i} \\
0.5478-0.2079\mathit{i} & -0.0609+0.1265\mathit{i} & -0.7981+0.0\mathit{i} \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
\left[
\begin{array}{ccc}
-0.2586+0.0\mathit{i} & 0.5478+0.2079\mathit{i} & 0.5478-0.2079\mathit{i} \\
-0.804+0.0\mathit{i} & -0.0609-0.1265\mathit{i} & -0.0609+0.1265\mathit{i} \\
-0.5354+0.0\mathit{i} & -0.7981+0.0\mathit{i} & -0.7981+0.0\mathit{i} \\
\end{array}
\right]
\end{equation}
")
EMV=eigen((A+im*A)+(A+im*A)')
Eigen{ComplexF64, Float64, Matrix{ComplexF64}, Vector{Float64}}
values:
3-element Vector{Float64}:
 -3.8596953069823394
  0.8685009737929961
 36.99119433318928
vectors:
3×3 Matrix{ComplexF64}:
 -0.905599-0.00361395im   -0.16496-0.118296im    -0.365486+0.0713593im
 0.0510555+0.125175im     0.852368+0.00319519im  -0.501256+0.0626551im
  0.401998-0.0im         -0.481926-0.0im         -0.778553-0.0im
(L"\begin{equation}
\left[
\begin{array}{ccc}
2.0+0.0\mathit{i} & 7.0-1.0\mathit{i} & 12.0-2.0\mathit{i} \\
7.0+1.0\mathit{i} & 10.0+0.0\mathit{i} & 14.0-2.0\mathit{i} \\
12.0+2.0\mathit{i} & 14.0+2.0\mathit{i} & 22.0+0.0\mathit{i} \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
\left[
\begin{array}{ccc}
-0.9056-0.0036\mathit{i} & -0.165-0.1183\mathit{i} & -0.3655+0.0714\mathit{i} \\
0.0511+0.1252\mathit{i} & 0.8524+0.0032\mathit{i} & -0.5013+0.0627\mathit{i} \\
0.402+0.0\mathit{i} & -0.4819+0.0\mathit{i} & -0.7786+0.0\mathit{i} \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
\left[
\begin{array}{c}
-3.8597 \\
0.8685 \\
36.9912 \\
\end{array}
\right]
\end{equation}
")
(L"\begin{equation}
\left[
\begin{array}{ccc}
2.0+0.0\mathit{i} & 7.0+1.0\mathit{i} & 12.0+2.0\mathit{i} \\
7.0-1.0\mathit{i} & 10.0+0.0\mathit{i} & 14.0+2.0\mathit{i} \\
12.0-2.0\mathit{i} & 14.0-2.0\mathit{i} & 22.0+0.0\mathit{i} \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
\left[
\begin{array}{ccc}
-0.9056+0.0036\mathit{i} & -0.165+0.1183\mathit{i} & -0.3655-0.0714\mathit{i} \\
0.0511-0.1252\mathit{i} & 0.8524-0.0032\mathit{i} & -0.5013-0.0627\mathit{i} \\
0.402+0.0\mathit{i} & -0.4819+0.0\mathit{i} & -0.7786+0.0\mathit{i} \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
\left[
\begin{array}{c}
-3.8597 \\
0.8685 \\
36.9912 \\
\end{array}
\right]
\end{equation}
")
(L"\begin{equation}
\left[
\begin{array}{ccc}
-2.0\mathit{i} & -1.0-7.0\mathit{i} & -2.0-12.0\mathit{i} \\
1.0-7.0\mathit{i} & -10.0\mathit{i} & -2.0-14.0\mathit{i} \\
2.0-12.0\mathit{i} & 2.0-14.0\mathit{i} & -22.0\mathit{i} \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
\left[
\begin{array}{ccc}
0.9056+0.0\mathit{i} & 0.3655-0.0714\mathit{i} & -0.1654-0.1177\mathit{i} \\
-0.0516-0.125\mathit{i} & 0.5013-0.0627\mathit{i} & 0.8524+0.0\mathit{i} \\
-0.402+0.0016\mathit{i} & 0.7786+0.0\mathit{i} & -0.4819+0.0018\mathit{i} \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
\left[
\begin{array}{c}
3.8597\mathit{i} \\
-36.9912\mathit{i} \\
-0.8685\mathit{i} \\
\end{array}
\right]
\end{equation}
")
(L"$1+5\mathit{i}$", L"$1+5\mathit{i}$", L"$1-5\mathit{i}$")
pascal (generic function with 1 method)
Pas=pascal(5)
6×6 Matrix{Int64}:
 1  0   0   0  0  0
 1  1   0   0  0  0
 1  2   1   0  0  0
 1  3   3   1  0  0
 1  4   6   4  1  0
 1  5  10  10  5  1
Pas-Pas'
6×6 Matrix{Int64}:
 0  -1  -1  -1  -1   -1
 1   0  -2  -3  -4   -5
 1   2   0  -3  -6  -10
 1   3   3   0  -4  -10
 1   4   6   4   0   -5
 1   5  10  10   5    0
begin
PasE=eigen(Pas-Pas')
@printf "%s " "eigenvalues pasc - pasc^T "
latexify(["eigenvalues-pasc-pasc'" ~ round4.(PasE.values)])
end

$$\begin{align} eigenvalues - pasc - pasc' =& \left[ \begin{array}{c} -18.5547\mathit{i} \\ 18.5547\mathit{i} \\ -0.1954\mathit{i} \\ 0.1954\mathit{i} \\ -0.8277\mathit{i} \\ 0.8277\mathit{i} \\ \end{array} \right] \end{align}$$

begin
    function rotating_matrices3d(α,β,θ)
        matz=[cos(θ) -sin(θ) 0.0; sin(θ) cos(θ) 0.0; 0.0 0.0 1.0];
        matx=[1.0 0.0 0.0;0.0 cos(α) -sin(α); 0.0 sin(α) cos(α)];
        maty=[cos(β) 0.0 sin(β); 0.0 1.0 0.0; -sin(β) 0.0 cos(β)];
        return matx,maty,matz
    end
end
         
rotating_matrices3d (generic function with 1 method)
mat3d=rotating_matrices3d(0.0,π/2,π/2);
(L"\begin{equation}
I = \left[
\begin{array}{ccc}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
rotz = \left[
\begin{array}{ccc}
0 & -1 & 0 \\
1 & 0 & 0 \\
0 & 0 & 1 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
rotx = \left[
\begin{array}{ccc}
1 & 0 & 0 \\
0 & 1 & -0 \\
0 & 0 & 1 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
roty = \left[
\begin{array}{ccc}
0 & 0 & 1 \\
0 & 1 & 0 \\
-1 & 0 & 0 \\
\end{array}
\right]
\end{equation}
")
@bind rotind PlutoUI.Slider([[rand(1:3),rand(1:3),rand(1:3)] for i =1:100],show_value=true,default=1)
[1, 2, 1]
begin
ff2 = Figure(size=(500,500))
ax10=Axis3(ff2[1, 1], backgroundcolor = "beige")
vec0= [Point3f(x, y, z) for x in [0.0] for y in [0.0] for z in [0.0]]
vec10= map(x -> Vec3f(1.0, 0.5, 0.5), vec0)
v10=map(x -> Vec3f(mat3d[rotind[1]]*mat3d[rotind[2]]*mat3d[rotind[3]]*vec10[1]),vec0)
#vec10=Vec3f([10,10,10])
#strength10 = norm(v10)
#arrows!(ax10,vec0,vec10, fxaa=true, arrowsize =0.05 , lengthscale =1.0,linecolor = :black, arrowcolor =:blue,linewidth = 0.025,align = :origin)

#arrows!(ax10,vec0,v10, fxaa=true, arrowsize =0.05 , lengthscale =1.0 ,linecolor = :green, arrowcolor =:red,linewidth = 0.025,align = :origin)

arrows!(ax10,vec0,vec10,align=:origin,linewidth = 0.05,arrowsize = Vec3f(0.2, 0.2, 0.2))
arrows!(ax10,vec0,v10,align=:origin,linecolor=:red,linewidth = 0.05,arrowsize = Vec3f(0.2, 0.2, 0.2))
xlims!(-2, 2)
ylims!(-2, 2)
zlims!(-2,2)
ff2
end
begin
latexify("orig" ~ vec10),
latexify("rotated" ~ v10);
end
(L"\begin{equation}
orig = \left[
\begin{array}{c}
\left[
\begin{array}{c}
1 \\
0.5 \\
0.5 \\
\end{array}
\right] \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
rotated = \left[
\begin{array}{c}
\left[
\begin{array}{c}
0.5 \\
0.5 \\
-1 \\
\end{array}
\right] \\
\end{array}
\right]
\end{equation}
")
begin
ff3=Figure(size=(500,500))
ax11=Axis3(ff3[1, 1], backgroundcolor = "beige")
ps = [Point3f(x1, y1, z1) for x1 in -10:2:10 for y1 in -10:2:10 for z1 in -10:2:10];
L=10.0
ns = map(p -> Vec3f(sin(p[1]*π/L)*cos(p[2]*π/L), -sin(p[2]*π/L)*cos(p[1]*π/L), p[3]*π/L), ps);
arrows!(
           ps, ns, fxaa=true, # turn on anti-aliasing
           linecolor = :red, arrowcolor = :black,
           linewidth = 0.1, arrowsize = Vec3f(0.3, 0.3, 0.4),
           align = :center)#,axis=(type=Axis3,))
ff3
end

MATRICES,NÚMEROS COMPLEJOS Y ROTACIONES

begin
@variables β[1:2], γ[1:2]
function δ(β,γ)
#	(β[1] +im*β[2])*(γ[1]+ im*γ[2])
    complex(β[1],β[2])*complex(γ[1],γ[2])
end
δ1=δ(β,γ)
#latexify("δ" ~ (β[1] +im*β[2])*(γ[1]+ im*γ[2])),
latexify(" δ = δ(β,γ) "), # ~ real(δ1) + (im)*imag(δ1))#+ im*δ1[2]])
#latexify(" = "),
latexify(δ(β,γ))

end
(L"$\delta = \delta\left( \beta, \gamma \right)$", L"\begin{equation}
\beta_1 \gamma_1 - \beta_2 \gamma_2 + \left( \beta_1 \gamma_2 + \beta_2 \gamma_1 \right) \mathit{i}
\end{equation}
")
latexify(δ([0;1.0],[0.0,1.0]))

$$-1.0+0.0\mathit{i}$$

begin
Β(β)=[β[1] -β[2]; β[2] β[1] ]
Γ(γ)=[γ[1] -γ[2]; γ[2] γ[1] ]
latexify("Γ" ~ Γ(γ)),
latexify("β" ~ Β(β)),
#latexify("βΓ" ~ Β([0.0;1.0])*Γ([1.0,0.0]))
latexify("βΓ" ~ Β(β)*Γ(γ))

end
(L"\begin{equation}
\Gamma = \left[
\begin{array}{cc}
\gamma_1 &  - \gamma_2 \\
\gamma_2 & \gamma_1 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
\beta = \left[
\begin{array}{cc}
\beta_1 &  - \beta_2 \\
\beta_2 & \beta_1 \\
\end{array}
\right]
\end{equation}
", L"\begin{equation}
\beta\Gamma = \left[
\begin{array}{cc}
\beta_1 \gamma_1 - \beta_2 \gamma_2 &  - \beta_1 \gamma_2 - \beta_2 \gamma_1 \\
\beta_1 \gamma_2 + \beta_2 \gamma_1 & \beta_1 \gamma_1 - \beta_2 \gamma_2 \\
\end{array}
\right]
\end{equation}
")
begin
    @variables ϕ
    function expΩ(ϕ)
        cos(ϕ)*I(2)+ sin(ϕ)*[0.0 -1.0;1.0 0.0]
    end
(Β([0.0, 1.0]))*[1.0;0.0]
end
2-element Vector{Float64}:
 0.0
 1.0
latexify(round4.(expΩ(pi)))
#Β([0.0, 1.0])*ϕ

$$\begin{equation} \left[ \begin{array}{cc} -1.0 & 0.0 \\ 0.0 & -1.0 \\ \end{array} \right] \end{equation}$$

begin
ϵ(ϕ)=(Β([0.0, 1.0]))*ϕ
function mexp(ϵ)
    cos(ϕ)*I(2)+ sin(ϕ)*[0.0 -1.0;1.0 0.0]
end
end
mexp (generic function with 1 method)
exp.(ϵ(ϕ))

$$\begin{equation} \left[ \begin{array}{cc} 1 & e^{ - \phi} \\ e^{\phi} & 1 \\ \end{array} \right] \end{equation}$$

mexp(ϵ(ϕ))

$$\begin{equation} \left[ \begin{array}{cc} \cos\left( \phi \right) & - \sin\left( \phi \right) \\ \sin\left( \phi \right) & \cos\left( \phi \right) \\ \end{array} \right] \end{equation}$$

Built with Julia 1.10.0 and

Krylov 0.9.5
Latexify 0.16.1
LinearSolve 2.22.1
PlutoUI 0.7.55
Symbolics 5.14.1
WGLMakie 0.9.4

To run this tutorial locally, download [this file](/tutorials/algebralineal.jl) and open it with Pluto.jl._